from diffusers import StableDiffusionXLPipeline,EulerDiscreteScheduler
import torch

def generate_img():
    repo_id = "SG161222/RealVisXL_V3.0"
    scheduler = EulerDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
    pipeline = StableDiffusionXLPipeline.from_pretrained(
        repo_id,
        scheduler=scheduler,
        use_safetensors=True,
        torch_dtype=torch.bfloat16 #降低精度
    ).to("cuda")
    pipeline.load_textual_inversion("DarkAngelH/EasyNegative", weight_name="easynegative.safetensors", token="EasyNegative")
    #prompt = "an orange color cat, solo, detailed, 8k"
    prompt = "1girl, solo, detailed, 8k"
    image = pipeline(prompt=prompt,negative_prompt = "EasyNegative", guidance_scale=7.5, num_inference_steps=30,width=640,height=640).images[0]
    return image

image = generate_img()
#image.save("tmp/c03.png")
image.save("tmp/person2.png")